﻿using Autofac;
using Autofac.Features.OwnedInstances;
using System;
using System.Collections.Generic;
using System.Text;

namespace PlutoStudio.Dependency
{
    internal class DisposableDependencyObjectWrapper : DisposableDependencyObjectWrapper<object>, IDisposableDependencyObjectWrapper
    {
        public DisposableDependencyObjectWrapper(ILifetimeScope lifetime,object obj)
            : base(lifetime, obj)
        {

        }
    }

    internal class DisposableDependencyObjectWrapper<T> : IDisposableDependencyObjectWrapper<T>
    {
        private readonly ILifetimeScope _lifetime;
        private readonly T _value;
        public T Value => _value;

        public DisposableDependencyObjectWrapper(ILifetimeScope lifetime, T obj)
        {
            _lifetime = lifetime;
            _value = obj;
        }

        public void Dispose()
        {
            _lifetime.Dispose();
        }
    }
}
